package pl.extremme.robocode.utils;

import java.util.logging.Logger;

/**
 * Represent a podouble in the cartesian coordinate system. Please remember that
 * (X, Y) have to be positive. And (0, 0) is in lower left of the screen.
 * Positive infinity is the upper right of the screen.
 *
 * @author XyC
 */
class CartesianPoint {

    private double x;
    private double y;
    private Logger log;

    public CartesianPoint() {
        this.log = Logger.getLogger(CartesianPoint.class.getName());
        this.log.entering(CartesianPoint.class.getName(), CartesianPoint.class.getSimpleName());
        this.log.info("Initializing (X, Y) to (0, 0)...");
        this.x = 0;
        this.y = 0;
        this.log.exiting(CartesianPoint.class.getName(), CartesianPoint.class.getSimpleName());
    }

    public CartesianPoint(double x, double y) {
        this.log = Logger.getLogger(CartesianPoint.class.getName());
        this.x = x;
        this.y = y;
    }

    public double getX() {
        return this.x;
    }

    public double getY() {
        return this.y;
    }

    public void setX(double p_X) {
        if(p_X < 0) {
            throw new ArithmeticException("X has to be positive");
        }
        this.x = p_X;
    }

    public void setY(double p_Y) {
        if(p_Y < 0) {
            throw new ArithmeticException("Y has to be positive");
        }
        this.y = p_Y;
    }

    @Override
    public String toString() {
        return "(X, Y) => (" + this.getX() + ", " + this.getY() + ")";
    }

    @Override
    public boolean equals(Object obj) {
        boolean ret = false;
        if(obj instanceof CartesianPoint) {
            CartesianPoint other = (CartesianPoint)obj;
            if(other.getX() == this.getX() && other.getY() == this.getY()) {
                ret = true;
            }
        }
        return ret;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
        hash = 83 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
        return hash;
    }

}
